
package cn.klandor.picasa.ui;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JToolBar;

import javax.swing.JPanel;

public class ControlPanel extends JPanel {
	
	private static final long serialVersionUID = 1L;
	private PhotoChooser photoChooser;
	private PhotoPanel photoPanel;
	private JButton jpb ;

	public PhotoChooser getPhotoChooser() {
		return photoChooser;
	}

	public void setPhotoChooser(PhotoChooser photoChooser) {
		this.photoChooser = photoChooser;
	}

	public PhotoPanel getPhotoPanel() {
		return photoPanel;
	}

	public void setPhotoPanel(PhotoPanel photoPanel) {
		this.photoPanel = photoPanel;
	}

	public ControlPanel(PhotoChooser photoChooser,
						PhotoPanel photoPanel){
		super(new BorderLayout());
		this.photoChooser = photoChooser;
		this.photoPanel = photoPanel;
		this.add(getPanel(),BorderLayout.SOUTH);
	}
	
	private Component getPanel() {
		JPanel controlLabel = new JPanel(new FlowLayout()){

			private static final long serialVersionUID = 1L;

			public boolean isOpaque() {
		        return false;
		    }
		};
		JToolBar tb = new JToolBar();
		tb.setFloatable(false);
		tb.setBorder(BorderFactory.createEtchedBorder());
		
		JButton One2One = new JButton(new ImageIcon(getClass().getResource("/res/oo.png")));
		One2One.addActionListener(new ActionListener(){

			public void actionPerformed(ActionEvent arg0) {
				
				photoPanel.zoomO();
			}
			
		});
		tb.add(One2One);
		tb.addSeparator();
		JButton up = new JButton(new ImageIcon(getClass().getResource("/res/in.png")));
		up.addActionListener(new ActionListener(){

			public void actionPerformed(ActionEvent arg0) {
				
				photoPanel.zoomUp();
			}
			
		});
		tb.add(up);
		
		JButton down = new JButton(new ImageIcon(getClass().getResource("/res/out.png")));
		down.setPreferredSize(new Dimension(30, 20));
		down.addActionListener(new ActionListener(){

			public void actionPerformed(ActionEvent arg0) {
				
				photoPanel.zoomIn();
			}
			
		});
		tb.add(down);
		tb.addSeparator();

		JButton pre = new JButton(new ImageIcon(getClass().getResource("/res/pre.png")));
		pre.addActionListener(new ActionListener(){

			public void actionPerformed(ActionEvent arg0) {
				
				photoChooser.setPhotoIndex(photoChooser.getPhotoIndex()-1);
			}
			
		});
		tb.add(pre);
		
		JButton next = new JButton(new ImageIcon(getClass().getResource("/res/next.png")));
		next.addActionListener(new ActionListener(){

			public void actionPerformed(ActionEvent arg0) {
				
				photoChooser.setPhotoIndex(photoChooser.getPhotoIndex()+1);
			}
			
		});
		tb.add(next);
		tb.addSeparator();
		
		JButton lRoll = new JButton(new ImageIcon(getClass().getResource("/res/right.png")));
		lRoll.addActionListener(new ActionListener(){

			public void actionPerformed(ActionEvent arg0) {
				
				photoPanel.rotateLeft();
			}
			
		});
		tb.add(lRoll);
		
		JButton rRoll = new JButton(new ImageIcon(getClass().getResource("/res/left.png")));
		rRoll.addActionListener(new ActionListener(){

			public void actionPerformed(ActionEvent arg0) {
				
				photoPanel.rotateRight();
			}
			
		});
		tb.add(rRoll);
		tb.addSeparator();
		
		jpb = new JButton(new ImageIcon(getClass().getResource("/res/star.png")));

		tb.add(jpb);
		controlLabel.add(tb);
		
		return controlLabel;
	}
	

	public boolean isOpaque() {
        return false;
    }
	public void addLoadAction(ActionListener l) {
        jpb.addActionListener(l);
    }

}
